﻿using System;
using System.Collections.Generic;
using DTO;
using System.Data;
using System.Data.SqlClient;

namespace DAO
{
    public class DAOPhanLop
    {
        public static object DanhSachHocSinhChuaCoLop(DTOHocSinh hocsinh)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                if (hocsinh.MaLop != null)
                    sqlParams.Add(new SqlParameter("@MALOP", hocsinh.MaLop));
                else
                    sqlParams.Add(new SqlParameter("@MALOP", ""));
                DataTable dt = SQLDataProvider.ExecuteQuery("sp_LietKeDanhSachHocSinhPhanLop", sqlParams);
                DataColumn columnChon = new DataColumn("IsCheck", System.Type.GetType("System.Boolean"));
                columnChon.DefaultValue = false;
                dt.Columns.Add(columnChon);
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static object DanhSachLop()
        {
            try
            {
                return SQLDataProvider.ExecuteQuery("sp_LietKeDanhSachLop");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static DataTable SiSoHienTai(string MaLop)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MALOP", MaLop));
                DataTable dt = SQLDataProvider.ExecuteQuery("sp_KiemTraSiSoHienTai", sqlParams);
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static int CapNhatLopHocSinh(DTOHocSinh hocsinh)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MAHS", hocsinh.MaHS));
                if (hocsinh.MaLop == null)
                    sqlParams.Add(new SqlParameter("@MALOP", ""));
                else
                    sqlParams.Add(new SqlParameter("@MALOP", hocsinh.MaLop));
                return SQLDataProvider.ExecuteNoneQuery("sp_CapNhatLop", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


    }
}
